﻿
// MailSlotSrvView.cpp: CMailSlotSrvView 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MailSlotSrv.h"
#endif

#include "MailSlotSrvDoc.h"
#include "MailSlotSrvView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMailSlotSrvView

IMPLEMENT_DYNCREATE(CMailSlotSrvView, CView)

BEGIN_MESSAGE_MAP(CMailSlotSrvView, CView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
	ON_COMMAND(IDM_SLOT_RECV, &CMailSlotSrvView::OnSlotRecv)
END_MESSAGE_MAP()

// CMailSlotSrvView 构造/析构

CMailSlotSrvView::CMailSlotSrvView() noexcept
{
	// TODO: 在此处添加构造代码

}

CMailSlotSrvView::~CMailSlotSrvView()
{
}

BOOL CMailSlotSrvView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CView::PreCreateWindow(cs);
}

// CMailSlotSrvView 绘图

void CMailSlotSrvView::OnDraw(CDC* /*pDC*/)
{
	CMailSlotSrvDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: 在此处为本机数据添加绘制代码
}


// CMailSlotSrvView 打印

BOOL CMailSlotSrvView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CMailSlotSrvView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void CMailSlotSrvView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清理过程
}


// CMailSlotSrvView 诊断

#ifdef _DEBUG
void CMailSlotSrvView::AssertValid() const
{
	CView::AssertValid();
}

void CMailSlotSrvView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMailSlotSrvDoc* CMailSlotSrvView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMailSlotSrvDoc)));
	return (CMailSlotSrvDoc*)m_pDocument;
}
#endif //_DEBUG


// CMailSlotSrvView 消息处理程序


void CMailSlotSrvView::OnSlotRecv()
{
	// TODO: 在此添加命令处理程序代码
	HANDLE hMailSolt;
	hMailSolt = CreateMailslot("\\\\.\\mailslot\\MyMailSlot", 0, MAILSLOT_WAIT_FOREVER, NULL);
	if (INVALID_HANDLE_VALUE == hMailSolt)
	{
		MessageBox("创建油槽失败！");
		return;
	}
	char buf[100];
	DWORD dwRead;
	if (!ReadFile(hMailSolt, buf, 100, &dwRead, nullptr))
	{
		MessageBox("创建油槽失败！");
		CloseHandle(hMailSolt);
		return;
	}
	MessageBox(buf);
	CloseHandle(hMailSolt);
}
